/**
 * Qua that khong nghi ra cach nao de co the toan hoa' duoc cai nay.
 * chi co 1 ket luan nho la cac so co index : 1, 4, 7... la nhung so chan :3
 * => Liet ke tat ca so fibo < 4 trieu
 * => Tinh tong voi cai ket luan tren.
 * Any others????
 * @author TrinhNX
 */
public class Euler002 {

	public static void main(String[] args) {
		final int MAX = 50; // cho max = 50 phan tu, vi phu thuoc vao 4 trieu
		int[] arrayFibor = new int[MAX];
		// INPUT:
		final int MARK = 4000000; // Mark 4000000 la dung
		arrayFibor[0] = 1;
		arrayFibor[1] = 2;
		int index = 2;
		do {
			arrayFibor[index] = arrayFibor[index - 1] + arrayFibor[index - 2];
		} while (arrayFibor[index++] < MARK);
		System.out.println("index: " + index);
		int sum = 0;
		// Here, we subtract 1 because the last one is always bigger than 4mil 
		// (see the condition and do-while()
		for (int i = 1; i < index - 1; i = i + 3) {
			sum = sum + arrayFibor[i];
		}
		System.out.println("Sum	: " + sum);
		arrayFibor[0] = 1;
		arrayFibor[1] = 2;
		index = 2;
		sum = 0;
		do {
			arrayFibor[index] = arrayFibor[index - 1] + arrayFibor[index - 2];
			if ((index - 1) % 3 == 0) {
				sum = sum + arrayFibor[index];
			}
		} while (arrayFibor[index++] < MARK);
		// 
		System.out.println("index: " + index + "\tSum" + (sum + arrayFibor[1]));
	}

}
